import request from '@/utils/request'

/**
 * 获取类别树
 * @returns
 */
export function queryCategoryTree() {
  return request.get(`/category/list/tree`);
}

// 查询类别详细
export function listAll(data) {
  return request({
    url: '/category/list/page',
    method: 'post',
    data: data
  })
}
// 查询父级类别
export function listAllParent() {
  return request({
    url: '/category/list/parent',
    method: 'get'
  })
}
// 查询类别详细
export function getCategory(data) {
  return request({
    url: '/category/list/page/ro',
    method: 'post',
    data: data
  })
}
// 新增类别
export function addCategory(data) {
  return request({
    url: '/category/add',
    method: 'post',
    data: data
  })
}

// 修改类别
export function updateCategory(data) {
  return request({
    url: '/category/update',
    method: 'post',
    data: data
  })
}

// 批量删除类别
export function delCategorys(data) {
  return request({
    url: '/category/delete/list',
    method: 'post',
    data: data
  })
}
// 删除类别
export function delCategory(data) {
  return request({
    url: '/category/delete/long?categoryId=' + data,
    method: 'post'
  })
}

// 上传文件
export function uploadFile(file, uploadFileRequest) {
  const formData = new FormData()
  formData.append('file', file)
  for (const key in uploadFileRequest) {
    formData.append(key, uploadFileRequest[key])
  }
  return request({
    url: 'file/upload', // 确保这里匹配你的后端API路径
    method: 'post',
    data: formData
  })
}
